package glemipsc;

import glemipsc.implementations.Argument;

public class Address implements Comparable, Argument {
	private Integer address = 0;
	private Argument segment;
	
	public Address() {
		if (segment == null && address == 0) {
			segment = GLEMipsC.compiler.getEnvironment().implementation.getZeroRegister();
			address = 0;
		}
	}
	
	public Address(Argument segment, Integer offset) {
		this.segment = segment;
		this.address = offset;
	}
	
	public Argument getSegment() {
		return segment;
	}
	
	public void setSegment(Argument arg) {
		this.segment = arg;
	}
	
	public Argument getOffset() {
		return GLEMipsC.compiler.getEnvironment().implementation.getImmediate(address);
	}
	
	public int getValue() {
		return address;
	}
	
	public void setValue(int value) {
		this.address = value;
	}

	public int compareTo(Object o) {
		return address.compareTo(((Address)o).address);
	}
	
	public String toString() {
		return segment.toString() + "(" + this.address + ")";
	}
	
	public String getOpCode() {
		return GLEMipsC.compiler.getEnvironment().implementation.getImmediate(this.address).getOpCode();
	}
}
